ALTER VIEW [dbo].[View_FW_Function]
AS
SELECT ff.FunctionGUID,
       ff.ModuleGUID,
       ff.FunctionName,
       ff.FunctionCode,
       ff.FunctionUrl,
       ff.FunctionComments,
       ff.FunctionIsDisable,
       ff.FunctionHelpUrl,
       ff.TenantId,
       ff.CreateTime,
       ff.BuUnitGUID,
       ff.ParentGUID,
       ff.FullCode,
       ff.OrderCode,
       ff.Icon,
	   ff.FunctionFirstLeShort,
	   ff.FunctionPinYin,
       (
           SELECT TOP 1
                  ApplicationCode + '.' + A2MOrderCode
           FROM dbo.View_FW_Application2Module
           WHERE ModuleGUID = fm.ModuleGUID
       ) + '.' + ff.FullCode AS FunctionOrderCode,
       ffa.FunctionName AS ParentFunctionName,
       fm.ModuleName,
       STUFF(
       (
           SELECT ',' + CAST(ApplicationGUID AS VARCHAR(36))
           FROM [dbo].FW_Application2Module
           WHERE ModuleGUID = ff.ModuleGUID
           FOR XML PATH('')
       ),
       1,
       1,
       ''
            ) AS ApplicationGUIDs
FROM dbo.FW_Function ff
    LEFT JOIN dbo.FW_Function ffa
        ON ffa.FunctionGUID = ff.ParentGUID
    LEFT JOIN dbo.FW_Module fm
        ON fm.ModuleGUID = ff.ModuleGUID;